package com.ice.work.moment.ticket.controller;

import com.honeybee.cloud.framework.common.aop.Log;
import com.honeybee.cloud.framework.common.response.ResponseEntity;
import com.ice.work.moment.facade.ticket.controller.ITicketController;
import com.ice.work.moment.facade.ticket.dto.CarDTO;
import com.ice.work.moment.facade.ticket.dto.CookieDTO;
import com.ice.work.moment.facade.ticket.mapper.ParamConvertMapper;
import com.ice.work.moment.facade.ticket.param.QueryTicketParam;
import com.ice.work.moment.facade.ticket.request.QueryTicketRequest;
import com.ice.work.moment.ticket.service.ICookieService;
import com.ice.work.moment.ticket.service.ITicketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description user
 * @Author DELL
 * @Create 2019-05-17
 * @Since 1.0.0
 */
@RestController
@SuppressWarnings("unused")
public class TicketController implements ITicketController {

    @Autowired
    private ITicketService ticketService;
    @Autowired
    private ICookieService cookieService;

    @Override
    @Log(name = "查询车次车票信息")
    public ResponseEntity<List<CarDTO>> queryTicket(QueryTicketRequest request, String appKey) {
        CookieDTO cookieDTO = cookieService.findByAppKey(appKey);
        QueryTicketParam param = ParamConvertMapper.INSTANCE.toParam(request);
        List<CarDTO> carDTOs = ticketService.queryTicket(cookieDTO.getCookieStore(), param);
        return ResponseEntity.ok(ParamConvertMapper.INSTANCE.toVO(carDTOs));
    }
}
